package samsung.yx;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Poj1573 {
	static int row, col, staCol, data[][], Step = 0;
	static int path[][];

	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner(new FileInputStream(
				"C:\\Users\\tstcit\\Desktop\\samsung_yx\\Poj1573.txt"));
		// Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			row = sc.nextInt();
			col = sc.nextInt();
			staCol = sc.nextInt();
			if (row == 0 && col == 0 && staCol == 0) {
				break;
			}
			data = new int[row][col];
			path = new int[row * col][2];
			for (int i = 0; i < (row * col); i++) {
				path[i][0] = -1;
				path[i][1] = -1;
			}
			// N,S,E,W
			for (int i = 0; i < row; i++) {
				String str = sc.next();
				for (int j = 0; j < col; j++) {
					if (str.substring(j, j + 1).equals("N")
							|| str.substring(j, j + 1).equals("n")) {
						data[i][j] = 1;
					}
					if (str.substring(j, j + 1).equals("S")
							|| str.substring(j, j + 1).equals("s")) {
						data[i][j] = 2;
					}
					if (str.substring(j, j + 1).equals("E")
							|| str.substring(j, j + 1).equals("e")) {
						data[i][j] = 3;
					}
					if (str.substring(j, j + 1).equals("W")
							|| str.substring(j, j + 1).equals("w")) {
						data[i][j] = 4;
					}
					// System.out.print(data[i][j] + " ");
				}
				// System.out.println();
			}
			GoOut(data, 0, staCol - 1, 0);
		}
	}

	public static void GoOut(int data[][], int x, int y, int step) {
		if (x < 0 || y < 0 || x >= row || y >= col) {
			System.out.println(step + " step(s) to exit");
			return;
		}
		if (step > (row * col)) {
			return;
		}
		if (!isVis(x, y)) {
			path[step][0] = x;
			path[step][1] = y;
		} else {
			System.out.println(step - Step + " step(s)");
			return;
		}
		if (data[x][y] == 1) {
			x -= 1;
		} else if (data[x][y] == 2) {
			x += 1;
		} else if (data[x][y] == 3) {
			y += 1;
		} else if (data[x][y] == 4) {
			y -= 1;
		}
		GoOut(data, x, y, step + 1);
	}

	public static boolean isVis(int m, int n) {
		for (int i = 0; i < (row * col); i++) {
			if (path[i][0] == m && path[i][1] == n) {
				System.out.print(i + " step(s) before a loop of ");
				Step = i;
				return true;
			}
		}
		return false;
	}

}
